<?php

$mcrp = './';
include_once('functions/session.php');
include_once('skin/default.php');
include_once('functions/contests.php');

if(!isset($_GET['id']))
{
	$Error = 'Concours inexistant';
	$SkinTitle = 'µContest - Concours inexistant';
}
else
{
	$contest = GetContestById($_GET['id']);
	if($contest === false)
	{
		$Error = 'Concours inexistant';
		$SkinTitle = 'µContest - Concours inexistant';
	}
	else
	{
		if($contest->visible == 0 && $mcuser->isadmin == 0)
		{
			$Error = 'Concours inexistant';
			$SkinTitle = 'µContest - Concours inexistant';
		}
		else
		{
			$SkinTitle = 'µContest - ' . stripslashes($contest->title);
			$category = GetCategoryById($contest->category);
		}
	}
}

include_once('skin/header.php');

$UsersCount = GetActiveUsersCount();

?>

<div class="mc_box">
	<h3><?php if(isset($Error)) echo 'Erreur'; else echo '<a href="contests.php">Liste des épreuves</a> :: <a href="contests.php?id=' . $category->id . '">' . stripslashes($category->title) . '</a> :: ' . stripslashes($contest->title) . ' (' . $contest->id . ')'; ?><?php if($mcuser->isadmin) echo '<a href="admin/contestedit.php?id=' . $contest->id . '"><span style="padding-left:10px; font-size:.6em;">Edit</a></a>'; ?></h3>	
	<div class="mc_contest_view_text">
		<?php if(isset($Error)) echo "<font color=\"red\"><b>$Error</b></font>";
		else
		{
		?>
			<div id="mc_summary">
				<div style="float: right;"><?php if(IsValidated($mcuser, $contest->id)) echo '<img src="img/check.png" />'; ?></div>
				<h3>Résumé</h3>
				<table>
					<tr>
						<td>ID :</td>
						<td style="padding-left: 10px;"><?php echo $contest->id; ?></td>
					</tr>
					<tr>
						<td>Points :</td>
						<td style="padding-left: 10px;"><?php echo $contest->points ?></td>
					</tr>
					<tr>
						<td>Validations :</td>
						<td style="padding-left: 10px;"><?php echo round(100*$contest->validationcount/$UsersCount, 0); ?> %</td>
					</tr>
					<tr>
						<td colspan=2><a href="contests/<?php echo $contest->id; ?>/contest.php">Page de l'épreuve</a></td>
					</tr>
				</table>
			</div>
		
			<h3 style="margin-right:200px">Description</h3><br />
			<?php
				if($lang['lang'] == 'en' && $contest->description_en != null) $descr = $contest->description_en;
				else $descr = $contest->description;
				echo nl2br(stripslashes($descr));
			?>
			
			<br /><br />
			<h3>Variables</h3><br />
			<table id="mc_vars_table" class="mc_table">
				<tr>
					<th class="vt1">Nom</th>
					<th colspan=2>Type</th>
					<th class="vt4">Description</th>
				</tr>
				<tr class="mc_vars_type" >
					<td colspan=4>Variables à récupérer</td>
				</tr>
				<?php
				function DispVars($vars)
				{
					global $lang;
					$typehtml = array('int' => array('Entier', 'int', 'Integer'), 'char*' => array('Chaîne de caractères', 'char*', 'String'), 'float' => array('Réel', 'float', 'Real'));
					foreach($vars as $v)
					{
						if($v[1] == 'comment')
						{
							echo '<tr><td colspan=4>' . $v[2] . '</td></tr>';
						}
						else
						{
							echo '<tr><td class="vt1"><code>' . $v[0] . '</code></td>';
							if($lang['lang'] == 'en')
								echo '<td class="vt2">' . $typehtml[$v[1]][2] . '</td>';
							else
								echo '<td class="vt2">' . $typehtml[$v[1]][0] . '</td>';
							echo '<td class="vt3">' . $typehtml[$v[1]][1] . '</td>';
							if($lang['lang'] == 'en' && isset($v[3]))
								echo '<td class="vt4">' . $v[3] . '</td></tr>';
							else
								echo '<td class="vt4">' . $v[2] . '</td></tr>';
						}
					}
				}
				eval(stripslashes($contest->variables));
				DispVars($sentvars);
				?>
				<tr class="mc_vars_type">
					<td colspan=4>Variables à renvoyer</td>
				</tr>
				<?php
				DispVars($recvvars);
				?>
			</table>				
			<br /><br />
		<?php
		}
		?>
	</div>
</div>

<?php

include('skin/footer.php');

?>